package com.lkd.controller;

import com.lkd.dto.SkuClassDto;
import com.lkd.entity.SkuClass;

import com.lkd.service.ISkuClassService;
import com.lkd.vo.PageBean;
import com.lkd.vo.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
public class SkuClassController {

    private final ISkuClassService skuClassService;

    /**
     * 新增分类
     * @param skuClass
     * @return
     */
    @PostMapping("/api/vm-service/skuClass")
    public Result save(@RequestBody SkuClass skuClass ){
        skuClassService.save(skuClass);
        return Result.success();
    }

    /**
     * 分类搜索
     * @param skuClassDto
     * @return
     */
    @GetMapping("/api/vm-service/skuClass/search")
    public Result search(SkuClassDto skuClassDto){
        PageBean<SkuClass> pageBean = skuClassService.search(skuClassDto);
        return Result.success(pageBean);
    }

    /**
     * 根据id查询数据
     * @param classId
     * @return
     */
    @GetMapping("/api/vm-service/skuClass/{classId}")
    public Result findById(@PathVariable String classId){
        SkuClass byId = skuClassService.getById(classId);
        return Result.success(byId);
    }

    /**
     * 根据id修改数据
     * @param skuClass
     * @return
     */
    @PutMapping("/api/vm-service/skuClass")
    public Result update(@RequestBody SkuClass skuClass){
        skuClassService.updateById(skuClass);
        return Result.success();
    }

    /**
     * 根据id删除数据
     * @param classId
     * @return
     */
    @DeleteMapping("/api/vm-service/skuClass/{classId}")
    public Result delete(@PathVariable String classId){
        skuClassService.removeById(classId);
        return Result.success();
    }
}
